<!-- 添加用户 -->
<template>
  <div class="page-box  display-flex czbj">
    <p class="title-label mb10">
      用户管理 
    </p>
    <n-tabs type="line" size="medium" v-model:value="typjsre">
      <n-tab-pane :name="2" tab="员工" v-if="!bianjisd||typjsre==2">
        <n-form ref="formRef" :model="form" :rules="rules" label-width="120" :inline="false" size="normal"
          label-placement="left" class="mt20 sdfsdtrrter">
          <div class="kxzcrfecer">
            <n-grid :cols="24" :x-gap="20" :y-gap="20">
              <n-form-item-gi span="24" label="姓名:" path="name">
                <n-input type="text" placeholder="请输入姓名" size="medium" clearable v-model:value="form.name"></n-input>
              </n-form-item-gi>
              <n-form-item-gi span="24" label=" 员工编码:" path="employeeCode">
                <n-input type="text" placeholder="请输入员工编码" size="medium" clearable
                  v-model:value="form.employeeCode"></n-input>
              </n-form-item-gi>
              <n-form-item-gi span="24" label="手机:" path="phone">
                <n-input type="text" placeholder="请输入手机" size="medium" clearable v-model:value="form.phone"></n-input>

              </n-form-item-gi>
              <n-form-item-gi span="24" label="&nbsp;">
                <n-button type="primary" size="medium" @click="tijiaofrom">确认</n-button>
                <n-button size="medium" @click="callBack" class="ml20">关闭返回</n-button>
              </n-form-item-gi>
            </n-grid>
          </div>
        </n-form>
      </n-tab-pane>
      <n-tab-pane :name="1" tab="医生" v-if="!bianjisd||typjsre==1">

        <n-form ref="formRefys" :model="formys" :rules="rulesys" label-width="120" :inline="false" size="normal"
          label-placement="left" class="mt20 sdfsdtrrter">
          <div class="kxzcrfecer">
            <n-grid :cols="24" :x-gap="20" :y-gap="20">
              <n-form-item-gi span="24" label="姓名:" path="name">
                <n-input type="text" placeholder="请输入姓名" size="medium" clearable v-model:value="formys.name"></n-input>
              </n-form-item-gi>
              <n-form-item-gi span="24" label=" 省份:" path="province">
                <n-select size="medium" :options="options" clearable v-model:value="formys.province" />
              </n-form-item-gi>
              <n-form-item-gi span="24" label=" 医院:" path="hospital">
                <n-input type="text" placeholder="请输入医院" size="medium" clearable
                  v-model:value="formys.hospital"></n-input>
              </n-form-item-gi>
              <n-form-item-gi span="24" label="科室:" path="administrativeOffice">
                <n-input type="text" placeholder="请输入科室" size="medium" clearable
                  v-model:value="formys.administrativeOffice"></n-input>
              </n-form-item-gi>
              <n-form-item-gi span="24" label=" 职务:" path="post">
                <n-select size="medium" :options="optionszhiwu" clearable v-model:value="formys.post" />
              </n-form-item-gi>
              <n-form-item-gi span="24" label="手机:" path="phone">
                <n-input type="text" placeholder="请输入手机" size="medium" clearable v-model:value="formys.phone"></n-input>
                <div class="mt20">
                  <n-button type="primary" size="medium" @click="dfserxer">确认</n-button>
                  <n-button size="medium" @click="callBack" class="ml20">关闭返回</n-button>
                </div>
              </n-form-item-gi>
            </n-grid>
          </div>
        </n-form>
      </n-tab-pane>
    </n-tabs>
  </div>
</template>
<script lang='ts' setup>
import { ref } from "vue";
import { dxget, dxpost, qurl, hf, transferTimeYMDHm,callBack } from "../../../util/index";
const options = ref([])
const optionszhiwu = ref([])
const formRef = ref()
const formRefys = ref()
const cz = qurl()
const typjsre = ref()
const bianjisd = ref(false)
const form = ref({
  name: "",// 姓名
  employeeCode: "",//员工编号
  phone: "", //手机
  thenAdd: "phone",
  errmsg: "此手机号已注册，请勿重复注册",
  type: 2
})
const rules = ref({
  name: [
    {
      required: true,
      message: "请输入姓名",
    },
  ],
  employeeCode: [
    {
      required: true,
      message: "请输入员工编号",
    },
  ],
  phone: [
    {
      required: true,
      message: "请输入手机",
    },
  ],
})


const formys = ref({
  name: "",// 姓名
  province: "",//省份
  hospital: "",//医院
  administrativeOffice: "",//科室
  post: "",//职务
  phone: "", //手机
  thenAdd: "phone",
  errmsg: "此手机号已注册，请勿重复注册"
})
const rulesys = ref({
  name: [
    {
      required: true,
      message: "请输入姓名",
    },
  ],
  province: [
    {
      required: true,
      message: "请输入省份",
    },
  ],
  hospital: [
    {
      required: true,
      message: "请输入医院",
    },
  ],
  administrativeOffice: [
    {
      required: true,
      message: "请输入科室",
    },
  ],
  post: [
    {
      required: true,
      message: "请选择职务",
    },
  ],
  phone: [
    {
      required: true,
      message: "请输入phone",
    },
  ],
})

const xjdiqu = async () => {
  const { data }: any = await dxget("dxgjAdmin/getzd", { name: 'xjdiqu' })
  console.log(data);
  data.map(a => {
    a.value = a.label
  })
  options.value = data
}
xjdiqu()

const getxjyxzhiwu = async () => {
  const { data }: any = await dxget("dxgjAdmin/getzd", { name: 'xjyxzhiwu' })
  data.map(a => {
    a.value = a.label
  })
  optionszhiwu.value = data
}
getxjyxzhiwu()


const tijiaofrom = async () => {
  formRef.value?.validate(async (errors) => {
    const rest= await dxpost("xjyx/userList", form.value,cz.id?"put":"post")
    callBack()
    window.$message.success("提交成功！")
  })
}
const dfserxer = async () => {
  formRefys.value?.validate(async (errors) => {
    const rest= await dxpost("xjyx/userList",formys.value,cz.id?"put":"post")
    callBack()
    window.$message.success("提交成功！")
  })
}
const initData = async()=>{
  const {data}:any = await dxget("xjyx/userList",{id:cz.id})
  typjsre.value = data.type
  if(data.type==1){
    formys.value = data

  }else{
    form.value = data
  }
}
if(cz.id){
  bianjisd.value = true
  initData()
}
</script>
<style scoped>
.kxzcrfecer {
  width: 800px;
}</style>